package com.example.demo.service;

import com.example.demo.enums.BookStatus;
import com.example.demo.mapper.BookMapper;
import com.example.demo.model.BookInfo;
import com.example.demo.model.PageRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookService {
    @Autowired
    private BookMapper bookMapper;

    public Integer insertBook(BookInfo bookInfo) {
        return bookMapper.insertBook(bookInfo);
    }

    public List<BookInfo> selectBookInfoByPage(PageRequest pageRequest) {
        Integer offset = pageRequest.getOffset();
        Integer limit = pageRequest.getPageSize();
        List<BookInfo> bookList = bookMapper.selectBookInfoByPage(offset, limit);
        for(BookInfo bookInfo : bookList){
            bookInfo.setStatusCN(BookStatus.getStatusByCode(bookInfo.getStatus()).getDesc());
        }
        return bookList;
    }

    public Integer selectCount() {
        return bookMapper.selectCount();
    }

    public BookInfo selectBookById(Integer bookId) {
        return bookMapper.selectBookById(bookId);
    }

    public Integer updateBookInfoById(BookInfo bookInfo) {
        return bookMapper.updateBookInfoById(bookInfo);
    }

    public Integer deleteBookInfoByIds(List<Integer> ids) {
        return bookMapper.deleteBookInfoByIds(ids);
    }

    public Integer deleteBookInfoById(Integer id) {
        return bookMapper.deleteBookById(id);
    }
}
